﻿using System;
using System.Drawing;


namespace We.Moonlight.Geometry
{
    /// <summary>
    /// Calculate Angles and Distances
    /// </summary>
    public static class Delta
    {
        /// <summary>
        /// Calculate an Angle by the Vertex and One point for each of the Rays
        /// </summary>
        /// <param name="P1">a Point on a Ray cast from the Vertex</param>
        /// <param name="P2">a Diffrent Point ona a diffrent Ray cast from Vertex</param>
        /// <param name="Vertex">the Vertex of teh Angle</param>
        /// <returns>The Angle P1-Vertex-P2 in Radians</returns>
        public static double AngleBetween(Point P1, Point P2, Point Vertex)
        {
            return System.Windows.Vector.AngleBetween(new System.Windows.Vector(P1.X - Vertex.X, P1.Y - Vertex.Y), new System.Windows.Vector(P2.X - Vertex.X, P2.Y - Vertex.Y));
        }
        /// <summary>
        /// Calculates the Distance between two give Point
        /// </summary>
        /// <param name="P1">One Point, the Start</param>
        /// <param name="P2">Another Point, the Target</param>
        /// <returns>Distance between start and Target</returns>
        public static double DistanceBetween(Point P1, Point P2)
        {
            var dx = Math.Abs(P2.X - P1.X);
            var dy = Math.Abs(P2.Y - P1.Y);
            return (double)Math.Sqrt(dx * dx + dy + dy);
        }
        /// <summary>
        /// Calculates the Point in the Center of a Rectangle
        /// </summary>
        /// <param name="R">the Rectangle to obtain the Center point from</param>
        /// <returns>the Point in or near (1 Pixel accuracy) the center of the rectangle</returns>
        public static Point CenterIn(Rectangle R)
        {
            return new Point(R.Width / 2, R.Height / 2);
        }
    }
}